package com.aiyige.page.edituserinfo;


import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.aiyige.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


public class EditBannerBottomDialog extends DialogFragment {
    Unbinder unbinder;
    Listener listener = null;
    int position;

    public EditBannerBottomDialog() {
    }

    public Listener getListener() {
        return listener;
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }


    public static EditBannerBottomDialog newInstance() {
        EditBannerBottomDialog fragment = new EditBannerBottomDialog();
        fragment.setStyle(STYLE_NORMAL, R.style.BottomDialogTheme);
        return fragment;
    }


    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.edit_banner_bottom_dialog, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        Window window = getDialog().getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
            window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.cancelBtn, R.id.editPhoto, R.id.editUrl, R.id.delete})
    public void onViewClicked(View view) {
        if (listener != null) {
            switch (view.getId()) {
                case R.id.editPhoto:
                    listener.editPhoto(position);
                    break;
                case R.id.editUrl:
                    listener.editUrl(position);
                    break;
                case R.id.delete:
                    listener.delete(position);
                    break;
                default:
                    break;
            }
        }
        dismiss();
    }

    public interface Listener {
        void editPhoto(int position);

        void editUrl(int position);

        void delete(int position);
    }
}
